package cn.edu.tju.core.utils;

public class HttpResult<T> {

    private Integer code;
    private String msg;
    private T data;

    // 现有的方法
    public static <T> HttpResult<T> ok(T data) {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(200);
        r.setMsg("success");
        r.setData(data);
        return r;
    }

    public static <T> HttpResult<T> ok() {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(200);
        r.setMsg("success");
        return r;
    }

    public static <T> HttpResult<T> fail(String msg) {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(400);
        r.setMsg(msg);
        return r;
    }

    // 新增 error 方法 - 解决报错的关键
    public static <T> HttpResult<T> error(String msg) {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(500); // 通常 error 使用 500 状态码
        r.setMsg(msg);
        return r;
    }

    // 新增的方法
    public static <T> HttpResult<T> success(String message, T data) {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(200);
        r.setMsg(message);
        r.setData(data);
        return r;
    }

    public static <T> HttpResult<T> success(String message) {
        HttpResult<T> r = new HttpResult<>();
        r.setCode(200);
        r.setMsg(message);
        return r;
    }

    // getter 和 setter
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}